package com.xiangyang.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xiangyang.annotations.OperationLog;
import com.xiangyang.entity.Drugs;
import com.xiangyang.entity.Employee;
import com.xiangyang.entity.dto.Result;
import com.xiangyang.mapper.IDrugsMapper;
import com.xiangyang.service.IDrugsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DrugsServiceimpl implements IDrugsService {
    @Autowired
    private IDrugsMapper drugsMapper;


    @Override
//    @OperationLog(title = "添加药品订单", businessType = "添加")
    public Result addDrugs(Drugs drugIds) {
            if (drugIds.getDrugNumbers() > 0 &&drugIds.getDrugNames()!=null
            && drugIds.getDrugShelfSecond()!=null && drugIds.getDrugMakers()!=null
            &&drugIds.getDrugDepicts()!=null && drugIds.getDrugPrices()!=null
            && drugIds.getDrugProductionDates()!=null) {
                int insert = drugsMapper.insertDrugs(drugIds);
                if (insert == 1) {
                    return Result.error("添加药品成功");
                }
    } else {
        return Result.error("药品数量必须大于0才能添加");
    }
            return Result.error("添加药品失败");
    }

    @Override
//    @OperationLog(title = "修改药品订单", businessType = "修改" , oldDataMethod = "getOldData", newDataMethod = "getNewData" )
    public Result updateDrugs(Drugs drugIds) {

        int drugId = drugsMapper.updateDrugs(drugIds);
        if(drugId>0){
            Drugs drugs=new Drugs();
            drugs.setDrugIds(drugs.getDrugIds());
            drugs.setDrugNumbers(drugIds.getDrugNumbers());
            UpdateWrapper<Drugs> updateWrapper=new UpdateWrapper<>();
            updateWrapper.eq("Drug_ids",drugIds);
//            int i = drugsMapper.updateById(drugId);
            return Result.ok("更新成功");
        }
         return Result.error("无效的药品ID，无法进行更新操作");
    }

    @Override
    public Result selectDrugName() {
        return Result.ok(drugsMapper.selectDoctor());
    }

    @Override
    public String removeDrugs(Long drugId) {
            if (drugId == null) {
            return "请输入要删除的药品编号";
        }
        int i = drugsMapper.deleteDrugs(drugId);
        return i > 0 ? "删除成功" : "删除失败";
    }


}

